﻿package org.dm.motion.effect 
{
	import flash.display.Sprite;
	/**
	 * ...
	 * @author Scott
	 */
	public class Smoking extends org.dm.motion.AnimateBase
	{
		private var numOfParticles:uint;
		private var particles:Array;
		
		public function Smoking(px:Number = 0, py:Number = 0; num:int = 60) 
		{			
			numOfParticles = 60;
			particles = [];
			_container = new Sprite();
			_container.x = px;
			_container.y = py;
			container.filters = [new flash.filters.BlurFilter(20,20,1)];
		}
		
		public function get display():Sprite 
		{ 
			return _container; 
		}
		
		public override function update():void
		{
			var trash:*;
			var particle:Smoke = new org.dm.motion.particles.Smoke();
			container.addChild(particle);
			//particle.x = 445-Math.random()*80;
			//particle.y = 270 - Math.random() * 8;
			
			particle.x = mouseX;
			particle.y = mouseY;
			//particle.gravity = -.1;
			//particle.friction = 1.02;
			particle.yVelocity = Math.random() * 1 - 2;
			particle.xVelocity = Math.random() * 2 - 1;
			particle.fade = .95;
			particle.alpha = Math.random() + .5;
			particle.scaleX = particle.scaleY = Math.random() * .5 + .5;
			particle.growX = 1.02;
			particle.growY = 1.02;
			particles.push(particle);
			while(particles.length > numOfParticles)
			{
				trash = particles.shift();
				container.removeChild(trash);
				trash = null;
			}
			for(var i:uint = 0; i < particles.length; i++)
			{
				particles[i].update();
				if(particles[i].alpha <= .01)
				{
					trash = particles[i];
					container.removeChild(particles.splice(i,1)[0]);
					trash = null;
				}
			}
		}
	}

}